/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;


import negocio.Solicitante;
import negocio.GestorSolicitante;
import negocio.Logueo;
import negocio.Logueos;
import datos.ProblemaDB;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.beans.PropertyVetoException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.table.DefaultTableModel;
import negocio.Coordinador;
import negocio.Operador;
import negocio.Validaciones;

/**
 *
 * @author INGENIERIA
 */
public class InterfazLogueo extends javax.swing.JInternalFrame {
    /////////////////s
    
    DefaultComboBoxModel modeloTipoCombo=new DefaultComboBoxModel(); 
    String cedula=null;
    String contrasenia=null;
    Coordinador coordinador=new Coordinador();
    Operador operador=new Operador();
    
    
    Logueos logueos=new Logueos();
    Logueo logueo=new Logueo();
    mipanel panelMenuI = new mipanel(490, 44,"/imagenes/tab_bar.jpg");
    mipanel bgrTitulo = new mipanel(821, 36,"/imagenes/title_panel1.jpg");
    ImageIcon ImgValido=new ImageIcon(getClass().getResource( "/Imagenes/CampoValido.jpg" ));
    ImageIcon ImgInvalido=new ImageIcon(getClass().getResource( "/Imagenes/CampoInvalido.jpg" ));
    boolean operacion=false;
    String nombreusuario;
    int tipousuario=0;
    JLabel nombredelusuario= new JLabel();
    JButton BotonCiudad=new JButton();
    JButton BotonCliente=new JButton();
    JButton BotonProducto=new JButton();
    JButton BotonFactura=new JButton();
    JButton BotonUsuario=new JButton();
    JButton BotonTipou=new JButton();
    JButton BotonLogueo=new JButton();
    JButton BotonProveedor=new JButton();
    JToggleButton BotonLista=new JToggleButton();
    Validaciones validacedula=new Validaciones();

    public JButton getBotonCiudad() {
        return BotonCiudad;
    }

    public void setBotonCiudad(JButton BotonCiudad) {
        this.BotonCiudad = BotonCiudad;
    }

    public JButton getBotonCliente() {
        return BotonCliente;
    }

    public void setBotonCliente(JButton BotonCliente) {
        this.BotonCliente = BotonCliente;
    }

    public JButton getBotonProducto() {
        return BotonProducto;
    }

    public void setBotonProducto(JButton BotonProducto) {
        this.BotonProducto = BotonProducto;
    }

    public JButton getBotonFactura() {
        return BotonFactura;
    }

    public void setBotonFactura(JButton BotonFactura) {
        this.BotonFactura = BotonFactura;
    }

    public JButton getBotonUsuario() {
        return BotonUsuario;
    }

    public void setBotonUsuario(JButton BotonUsuario) {
        this.BotonUsuario = BotonUsuario;
    }

    public JButton getBotonTipou() {
        return BotonTipou;
    }

    public void setBotonTipou(JButton BotonTipou) {
        this.BotonTipou = BotonTipou;
    }

    public JButton getBotonLogueo() {
        return BotonLogueo;
    }

    public void setBotonLogueo(JButton BotonLogueo) {
        this.BotonLogueo = BotonLogueo;
    }

    public JButton getBotonProveedor() {
        return BotonProveedor;
    }

    public void setBotonProveedor(JButton BotonProveedor) {
        this.BotonProveedor = BotonProveedor;
    }

    
    public JLabel getNombredelusuario() {
        return nombredelusuario;
    }

    public void setNombredelusuario(JLabel nombredelusuario) {
        this.nombredelusuario = nombredelusuario;
    }

    public JToggleButton getBotonLista() {
        return BotonLista;
    }

    public void setBotonLista(JToggleButton BotonLista) {
        this.BotonLista = BotonLista;
    }



    /**
     * Creates new form IngresoProyecto
     */
    public InterfazLogueo() {
        initComponents();
        pnlMensajes.setVisible(false);
        pnlIngreso.setVisible(true);
        jPanel1.add(bgrTitulo);
        jPanel1.repaint();
        valCel.setIcon(ImgInvalido);
        //pnlMensajes.add(panelMensajeI);
        //pnlMensajes.repaint();
        //pnlMenu.add(panelMenuI);
        //pnlMenu.repaint();
    
    }
        public boolean Validar()
    {
        boolean resp=false;
        if(valCel.getIcon().equals(ImgInvalido) )
        {
            resp=false;
        }
        else
        {
            resp=true;
        }
        return resp;
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlIngreso = new javax.swing.JPanel();
        lblNombre1 = new javax.swing.JLabel();
        lblCodigo1 = new javax.swing.JLabel();
        txtcedula = new javax.swing.JTextField();
        txtcontrasenia = new javax.swing.JTextField();
        btnGrabar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        valCel = new javax.swing.JLabel();
        combo_logueo = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        pnlMensajes = new javax.swing.JPanel();
        lblMensajes = new javax.swing.JLabel();
        btnCerrarMensajes = new javax.swing.JButton();
        lblVerificarr = new javax.swing.JLabel();

        setBackground(new java.awt.Color(250, 249, 242));
        setBorder(null);
        setForeground(new java.awt.Color(250, 250, 219));

        pnlIngreso.setBackground(new java.awt.Color(250, 247, 247));
        pnlIngreso.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Ingreso Al Sistema", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(0, 0, 0)));

        lblNombre1.setText("Contraseña:");

        lblCodigo1.setText("Cedula:");

        txtcedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtcedulaActionPerformed(evt);
            }
        });
        txtcedula.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtcedulaFocusLost(evt);
            }
        });

        txtcontrasenia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtcontraseniaActionPerformed(evt);
            }
        });
        txtcontrasenia.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtcontraseniaFocusLost(evt);
            }
        });

        btnGrabar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cmd_ingresar.jpg"))); // NOI18N
        btnGrabar.setBorder(null);
        btnGrabar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGrabarActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cmd_cancel.jpg"))); // NOI18N
        btnCancelar.setBorder(null);
        btnCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCancelarMouseClicked(evt);
            }
        });
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        valCel.setBackground(new java.awt.Color(250, 247, 247));
        valCel.setOpaque(true);

        combo_logueo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Operador", "Coordinador" }));
        combo_logueo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo_logueoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlIngresoLayout = new javax.swing.GroupLayout(pnlIngreso);
        pnlIngreso.setLayout(pnlIngresoLayout);
        pnlIngresoLayout.setHorizontalGroup(
            pnlIngresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlIngresoLayout.createSequentialGroup()
                .addGroup(pnlIngresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlIngresoLayout.createSequentialGroup()
                        .addGroup(pnlIngresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlIngresoLayout.createSequentialGroup()
                                .addGap(166, 166, 166)
                                .addComponent(lblCodigo1))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlIngresoLayout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(lblNombre1)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlIngresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtcedula, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                            .addComponent(txtcontrasenia))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(valCel, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(combo_logueo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlIngresoLayout.createSequentialGroup()
                        .addGap(108, 108, 108)
                        .addComponent(btnGrabar)
                        .addGap(61, 61, 61)
                        .addComponent(btnCancelar)))
                .addContainerGap(50, Short.MAX_VALUE))
        );
        pnlIngresoLayout.setVerticalGroup(
            pnlIngresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlIngresoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlIngresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlIngresoLayout.createSequentialGroup()
                        .addGroup(pnlIngresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblCodigo1)
                            .addComponent(valCel, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtcedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                        .addGroup(pnlIngresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtcontrasenia)
                            .addComponent(lblNombre1))
                        .addGap(102, 102, 102))
                    .addGroup(pnlIngresoLayout.createSequentialGroup()
                        .addComponent(combo_logueo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(pnlIngresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnGrabar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(33, 33, 33))
        );

        jPanel1.setBackground(new java.awt.Color(250, 249, 242));

        jLabel1.setText("LOGUEO");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 401, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(308, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlMensajes.setBackground(new java.awt.Color(250, 247, 247));
        pnlMensajes.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        lblMensajes.setBackground(new java.awt.Color(250, 247, 247));

        btnCerrarMensajes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cerrar.jpg"))); // NOI18N
        btnCerrarMensajes.setToolTipText("Cerrar Mensaje");
        btnCerrarMensajes.setBorder(null);
        btnCerrarMensajes.setOpaque(false);
        btnCerrarMensajes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCerrarMensajesActionPerformed(evt);
            }
        });

        lblVerificarr.setAutoscrolls(true);

        javax.swing.GroupLayout pnlMensajesLayout = new javax.swing.GroupLayout(pnlMensajes);
        pnlMensajes.setLayout(pnlMensajesLayout);
        pnlMensajesLayout.setHorizontalGroup(
            pnlMensajesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlMensajesLayout.createSequentialGroup()
                .addContainerGap(40, Short.MAX_VALUE)
                .addComponent(lblMensajes, javax.swing.GroupLayout.PREFERRED_SIZE, 393, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblVerificarr, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addComponent(btnCerrarMensajes))
        );
        pnlMensajesLayout.setVerticalGroup(
            pnlMensajesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlMensajesLayout.createSequentialGroup()
                .addGroup(pnlMensajesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblMensajes, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblVerificarr, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnCerrarMensajes, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(pnlMensajes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlIngreso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(96, 96, 96))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnlMensajes, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addComponent(pnlIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pnlIngreso.getAccessibleContext().setAccessibleName("Ingreso De Ciudades\n");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    private void jdcFechaInicioFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jdcFechaInicioFocusLost
        // TODO add your handling code here:

    }//GEN-LAST:event_jdcFechaInicioFocusLost

    private void jdcFechaInicioPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jdcFechaInicioPropertyChange
    }//GEN-LAST:event_jdcFechaInicioPropertyChange

    private void jdcFechaInicioInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_jdcFechaInicioInputMethodTextChanged
        // TODO add your handling code here:

    }//GEN-LAST:event_jdcFechaInicioInputMethodTextChanged

    private void jdcFechaInicioHierarchyChanged(java.awt.event.HierarchyEvent evt) {//GEN-FIRST:event_jdcFechaInicioHierarchyChanged
        // TODO add your handling code here:

    }//GEN-LAST:event_jdcFechaInicioHierarchyChanged

    private void jdcFechaInicioMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jdcFechaInicioMouseClicked
        // TODO add your handling code here:

    }//GEN-LAST:event_jdcFechaInicioMouseClicked

    private void jdcFechaTerminacionPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jdcFechaTerminacionPropertyChange
    }//GEN-LAST:event_jdcFechaTerminacionPropertyChange

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed

        // TODO add your handling code here:
        nombredelusuario.setText("");
        txtcedula.setText("");
        txtcontrasenia.setText("");
      BotonCiudad.setEnabled(false);
      BotonCliente.setEnabled(false);
      BotonFactura.setEnabled(false);
      BotonTipou.setEnabled(false);
      BotonUsuario.setEnabled(false);
      BotonProducto.setEnabled(false);
      BotonProveedor.setEnabled(false);
      BotonLista.setEnabled(false);
        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelarMouseClicked
        // TODO add your handling code here:
      
    }//GEN-LAST:event_btnCancelarMouseClicked

    private void btnGrabarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGrabarActionPerformed
        // TODO add your handling code here:
        String valor=combo_logueo.getSelectedItem().toString();
        Calendar Cal= Calendar.getInstance();
            String fechahora;
if (    "Coordinador".equals(valor)) {
if (Validar()==true){
            cedula = txtcedula.getText();
            contrasenia=txtcontrasenia.getText();
            fechahora= Cal.get(Cal.DATE)+"/"+(Cal.get(Cal.MONTH)+1)+"/"+Cal.get(Cal.YEAR)+" "+Cal.get(Cal.HOUR_OF_DAY)+":"+Cal.get(Cal.MINUTE)+":"+Cal.get(Cal.SECOND);
            logueo.setCedula(cedula);
            logueo.setFechahora(fechahora);
            coordinador=logueo.buscarCoordinador();

            if( coordinador==null) {
                lblMensajes.setText("El Coordinador no esta registrado");
            }
            else
                if(cedula.equals(coordinador.getCedula()) && contrasenia.equals(coordinador.getContrasenia()) )
                {
                  logueo.grabar();  
                  lblMensajes.setText("Usuario logueado Satisfactoriamente");
                  nombreusuario=coordinador.getNombre();
                  nombredelusuario.setText(nombreusuario);
                  lblVerificarr.setIcon(new ImageIcon( getClass().getResource( "/Imagenes/bien.jpg" )));
                  ///////llamar funcion
                   validarBotones();
                }else{
                    lblMensajes.setText("Verifique el usuario o contrasenia"); 
                    lblVerificarr.setIcon(new ImageIcon( getClass().getResource( "/Imagenes/Error.jpg" )));
                }
            
            
        } else{
            if(operacion==false) {
                lblMensajes.setText("Error: no se encuentra la cedula");
                valCel.setIcon(ImgInvalido);
                lblVerificarr.setIcon(new ImageIcon( getClass().getResource( "/Imagenes/Error.jpg" )));
            } 
            
        }
        pnlMensajes.setVisible(true);
    
}   else if ("Operador".equals(valor)) {
    if (Validar()==true){
            cedula = txtcedula.getText();
            contrasenia=txtcontrasenia.getText();
            fechahora= Cal.get(Cal.DATE)+"/"+(Cal.get(Cal.MONTH)+1)+"/"+Cal.get(Cal.YEAR)+" "+Cal.get(Cal.HOUR_OF_DAY)+":"+Cal.get(Cal.MINUTE)+":"+Cal.get(Cal.SECOND);
            logueo.setCedula(cedula);
            logueo.setFechahora(fechahora);
            operador=logueo.buscarOperador();

            if(operador==null) {
                lblMensajes.setText("El Operador no esta registrado");
            }
            else
                if(cedula.equals(operador.getCedula()) && contrasenia.equals(operador.getDireccion()) )
                {
                  logueo.grabar();  
                  lblMensajes.setText("Operador logueado Satisfactoriamente");
                  nombreusuario=operador.getNombre();
                  nombredelusuario.setText(nombreusuario);
                  lblVerificarr.setIcon(new ImageIcon( getClass().getResource( "/Imagenes/bien.jpg" )));
                  ///////llamar funcion
                   validarBotones();
                }else{
                    lblMensajes.setText("Verifique el usuario o contrasenia"); 
                    lblVerificarr.setIcon(new ImageIcon( getClass().getResource( "/Imagenes/Error.jpg" )));
                }
            
            
        } else{
            if(operacion==false) {
                lblMensajes.setText("Error: no se encuentra la cedula");
                valCel.setIcon(ImgInvalido);
                lblVerificarr.setIcon(new ImageIcon( getClass().getResource( "/Imagenes/Error.jpg" )));
            } 
            
        }
        pnlMensajes.setVisible(true);
    
}    
           
        
//        tipousuario=usuario.getTipoUsuario();
        //1 gerente 
        //2 administrador 
        //3 cajero      
        txtcedula.setText("");
        txtcontrasenia.setText("");
        
    }//GEN-LAST:event_btnGrabarActionPerformed

public void validarBotones()
{
      BotonCiudad.setEnabled(false);
      BotonCliente.setEnabled(false);
      BotonFactura.setEnabled(false);
      BotonTipou.setEnabled(false);
      BotonUsuario.setEnabled(false);
      BotonProducto.setEnabled(false);
      BotonProveedor.setEnabled(false);    
      BotonLista.setEnabled(false);    
  if (coordinador!=null)
  {
      BotonCiudad.setEnabled(true);
      BotonCliente.setEnabled(true);
      BotonFactura.setEnabled(true);
      BotonTipou.setEnabled(true);
      BotonUsuario.setEnabled(true);
      BotonProducto.setEnabled(true);
      BotonProveedor.setEnabled(true);
      BotonLista.setEnabled(true);
  }else 
  {
      if(operador!=null)
      {
      BotonCiudad.setEnabled(true);
      
      BotonCliente.setEnabled(true);
      BotonFactura.setEnabled(false);
      BotonTipou.setEnabled(true);
      BotonUsuario.setEnabled(true);
      BotonProducto.setEnabled(false);
      BotonProveedor.setEnabled(false); 
      BotonLista.setEnabled(false);
      }else
      {
//          if(usuario.getTipoUsuario()==3)
//          {
//                  BotonCiudad.setEnabled(false);
//                  BotonCliente.setEnabled(true);
//                  BotonFactura.setEnabled(true);
//                  BotonTipou.setEnabled(false);
//                  BotonUsuario.setEnabled(false);
//                  BotonProducto.setEnabled(false);
//                  BotonProveedor.setEnabled(false);
//                  BotonLista.setEnabled(false);
//          }
          System.out.println("NO HAY NI COORDINADOR NI OPERADOR");
      }
  
  }

}

public void agregarTipoUsuarioCombo()
    {
        modeloTipoCombo.removeAllElements();
        combo_logueo.addItem("Coordinador");
        combo_logueo.addItem("Operador");
        combo_logueo.setModel(modeloTipoCombo);    
    }
    
    private void txtcontraseniaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtcontraseniaFocusLost

    }//GEN-LAST:event_txtcontraseniaFocusLost

    private void txtcontraseniaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtcontraseniaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtcontraseniaActionPerformed

    private void txtcedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtcedulaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtcedulaActionPerformed

    private void txtcedulaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtcedulaFocusLost
        boolean valida=false;
        if(validacedula.validadorDeCedula(txtcedula.getText())==true)
        {
            valCel.setIcon(ImgValido);
        }
        else
        {
            valCel.setIcon(ImgInvalido);
            lblMensajes.setText("Error: Cedula Incorrecta");
            lblVerificarr.setIcon(new ImageIcon( getClass().getResource( "/Imagenes/Error.jpg" )));
            pnlMensajes.setVisible(true);
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_txtcedulaFocusLost

    private void btnCerrarMensajesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCerrarMensajesActionPerformed
        // TODO add your handling code here:
        lblMensajes.setText("");
        pnlMensajes.setVisible(false);
    }//GEN-LAST:event_btnCerrarMensajesActionPerformed

    private void combo_logueoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo_logueoActionPerformed

        
        // TODO add your handling code here:
    }//GEN-LAST:event_combo_logueoActionPerformed

    public class mipanel extends javax.swing.JPanel {
        String ruta;
        public mipanel(int ancho, int alto, String ruta){
            this.setSize(ancho,alto);
            this.ruta=ruta;           
        }

        @Override
        public void paint(Graphics g){
            
            Dimension tamanio = getSize();
            ImageIcon imagenFondo = new ImageIcon(getClass().getResource(ruta));
            g.drawImage(imagenFondo.getImage(),0,0,tamanio.width, tamanio.height, null);
            setOpaque(false);
            super.paintComponent(g);

        }        
    }
    
    

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnCerrarMensajes;
    private javax.swing.JButton btnGrabar;
    private javax.swing.JComboBox combo_logueo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblCodigo1;
    private javax.swing.JLabel lblMensajes;
    private javax.swing.JLabel lblNombre1;
    private javax.swing.JLabel lblVerificarr;
    private javax.swing.JPanel pnlIngreso;
    private javax.swing.JPanel pnlMensajes;
    private javax.swing.JTextField txtcedula;
    private javax.swing.JTextField txtcontrasenia;
    private javax.swing.JLabel valCel;
    // End of variables declaration//GEN-END:variables
}


